package com.hh.servlet.schedule;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hh.dao.ScheduleDAO;

/**
 * Servlet implementation class ScheduleUpdate
 */
@WebServlet("/ScheduleUpdate")
public class ScheduleUpdate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ScheduleUpdate() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		response.setHeader("content-type", "text/html;charset=UTF-8");
		String ygdm = request.getParameter("ygdm");
		String pbrq = request.getParameter("pbrq");
		String rq = request.getParameter("rq");
		ScheduleDAO dao = new ScheduleDAO();
		if(rq==null||rq.equals("")){
			dao.deleteSchedule(ygdm, pbrq);
			response.getWriter().print("删除成功");
		}else{
			String ksrq = rq.split("-")[0];
			String jsrq = rq.split("-")[1];
			if(dao.updateSchedule(ygdm, pbrq, ksrq, jsrq)){
				response.getWriter().print("修改成功");
			}else{
				dao.insertSchedule(ygdm, pbrq, ksrq, jsrq);
				response.getWriter().print("添加成功");
			}
			
		}
		
		
		
	}

}
